<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org"  xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('修改帖子内容')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-blogcontent-edit" th:object="${blogContent}">
            <input name="contentId" th:field="*{contentId}" type="hidden">
            <h4 class="form-header h4">基本信息</h4>
            <div class="row">
            	<div class="form-group col-sm-6">    
	                <label class="col-sm-2 control-label">标题：</label>
	                <div class="col-sm-8">
	                    <input name="title" th:field="*{title}" class="form-control" type="text">
	                </div>
	            </div>
	            <div class="form-group col-sm-6">    
	                <label class="col-sm-3 control-label textdanlan" title="选择正确的标签有助于提升帖子的曝光率哦...">标签：</label>
	                <div class="col-sm-8">
	                    <select name="tags" class="form-control m-b" th:with="type=${@dict.getType('blog_tags')}">
	                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{blogContent.tags}"></option>
	                    </select>
	                </div>
	            </div>
            </div>
            <div class="row">
            	<div class="form-group">    
	                <label class="col-sm-1 control-label">内容：</label>
	                <div class="col-sm-10">
	                    <input type="hidden" class="form-control" th:field="*{content}">
	                    <div class="summernote" id="content"></div>
	                </div>
	            </div>
            </div>
            <div class="row">
	            <div class="form-group col-sm-3">    
	                <label class="col-sm-5 control-label">开启评论：</label>
	                <div class="switch onoffswitch col-sm-1">
						<div class="onoffswitch">
							<input id="allowComment" name="allowComment" type="checkbox" value="1" class="onoffswitch-checkbox" th:checked=${blogContent.allowComment==1}> 
								<label class="onoffswitch-label" for="allowComment"> 
								<span class="onoffswitch-inner"></span> 
								<span class="onoffswitch-switch"></span>
							</label>
						</div>
					</div>
	            </div>
	            <div class="form-group col-sm-3">    
	                <label class="col-sm-5 control-label">是否发布：</label>
	                <div class="switch onoffswitch col-sm-1">
						<div class="onoffswitch">
							<input id="status" name="status" type="checkbox" class="onoffswitch-checkbox" value="1" th:checked=${blogContent.status==1}> 
								<label class="onoffswitch-label" for="status"> 
								<span class="onoffswitch-inner"></span> 
								<span class="onoffswitch-switch"></span>
							</label>
						</div>
					</div>
	            </div>
	            <div shiro:hasPermission="admin:admin:blog" class="form-group col-sm-3">    
	                <label class="col-sm-5 control-label">是否热门：</label>
	                <div class="switch onoffswitch col-sm-1">
						<div class="onoffswitch">
							<input id="ishot" name="ishot" type="checkbox" value="1" class="onoffswitch-checkbox" th:checked=${blogContent.ishot==1}> 
								<label class="onoffswitch-label" for="ishot"> 
								<span class="onoffswitch-inner"></span> 
								<span class="onoffswitch-switch"></span>
							</label>
						</div>
					</div>
	            </div>
	            <div shiro:hasPermission="admin:admin:blog" class="form-group col-sm-3">    
	                <label class="col-sm-5 control-label">是否工具：</label>
	                <div class="switch onoffswitch col-sm-1">
						<div class="onoffswitch">
							<input id="istool" name="istool" type="checkbox" value="1" class="onoffswitch-checkbox" th:checked=${blogContent.blogContent.istool==1}> 
								<label class="onoffswitch-label" for="istool"> 
								<span class="onoffswitch-inner"></span> 
								<span class="onoffswitch-switch"></span>
							</label>
						</div>
					</div>
	            </div>
	            <div shiro:hasPermission="admin:admin:blog" class="form-group col-sm-3">    
	                <label class="col-sm-3 control-label">类型：</label>
	                <div class="col-sm-8">
	                    <select name="type" class="form-control m-b" th:with="type=${@dict.getType('blog_type')}">
	                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{blogContent.type}"></option>
	                    </select>
	                </div>
	            </div>
            </div>
            <h4 class="form-header h4" shiro:hasPermission="admin:admin:blog">基本信息</h4>
            <div class="row" shiro:hasPermission="admin:admin:blog">
            	<!-- <div class="form-group col-sm-3">    
	                <label class="col-sm-5 control-label is-required">点击量：</label>
	                <div class="col-sm-7">
	                    <input name="views" th:field="*{views}" class="form-control" type="text" required>
	                </div>
	            </div>
	            <div class="form-group col-sm-3">    
	                <label class="col-sm-5 control-label is-required">点赞数：</label>
	                <div class="col-sm-7">
	                    <input name="zan" th:field="*{zan}" class="form-control" type="text" required>
	                </div>
	            </div> -->
            	<div class="form-group col-sm-3">    
	                <label class="col-sm-5 control-label is-required">点击量：</label>
	                <div class="col-sm-7">
	                    <input name="views" th:field="*{views}" class="form-control" type="text" required>
	                </div>
	            </div>
	            <div class="form-group col-sm-3">    
	                <label class="col-sm-5 control-label is-required">点赞数：</label>
	                <div class="col-sm-7">
	                    <input name="zan" th:field="*{zan}" class="form-control" type="text" required>
	                </div>
	            </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: summernote-js" />
    <script th:inline="javascript">
        var prefix = ctx + "blog/blogcontent";
        $("#form-blogcontent-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-blogcontent-edit').serialize());
            }
        }

        $("input[name='createDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='editDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $(function() {
            $('.summernote').each(function(i) {
                $('#' + this.id).summernote({
                    lang: 'zh-CN',
                    callbacks: {
                        onChange: function(contents, $edittable) {
                            $("input[name='" + this.id + "']").val(contents);
                        },
                        onImageUpload: function(files) {
							var obj = this;
							var data = new FormData();
							data.append("file", files[0]);
							$.ajax({
								type: "post",
								url: ctx + "common/upload",
								data: data,
								cache: false,
								contentType: false,
								processData: false,
								dataType: 'json',
								success: function(result) {
									if (result.code == web_status.SUCCESS) {
										$('#' + obj.id).summernote('insertImage', result.url);
									} else {
										$.modal.alertError(result.msg);
									}
								},
								error: function(error) {
									$.modal.alertWarning("图片上传失败。");
								}
							});
						}
                    }
                });
                var content = $("input[name='" + this.id + "']").val();
                $('#' + this.id).summernote('code', content);
            })
        });
    </script>
</body>
</html>